<template>
    <div class="exam-container">
      <el-descriptions title="新增职务" direction="vertical" :column="2" border>
        <!-- column为每行2列 如果列中将span设置为2 则何为1列 -->
  
        <el-descriptions-item label="名称" :width="750" :span="1">
          <el-input placeholder="在此输入组织名称" v-model="name"></el-input>
        </el-descriptions-item>
  
        <el-descriptions-item label="等级" :span="1">
          <el-input-number v-model="lv" style="width: 100%;" min="1" max="999"></el-input-number>
        </el-descriptions-item>
  
      
  
        <el-descriptions-item label="描述" :span="2">
          <el-input type="textarea" placeholder="组织描述" v-model="explain"></el-input>
        </el-descriptions-item>
  
        <el-descriptions-item label="" :span="2">
          <el-button
            type="primary"
            size="medium"
            @click="add"
            :disabled="name == ''"
            >新增</el-button
          >
        </el-descriptions-item>
      </el-descriptions>
    </div>
  </template>
    
    <script lang="ts">
  import { defineComponent, onMounted, reactive, toRefs } from 'vue'
  import { addZhiwu } from '../../api/org'
  import { ElMessage, ElMessageBox } from 'element-plus'
  import { useRoute, useRouter } from 'vue-router'
  import type addTreeOrgDto from '@/dto/org/addTreeOrgDto'
  
  export default defineComponent({
    setup() {
      const router = useRouter();
      const routes=useRoute();
      const data = reactive({
        name: '',
        explain: '',
        lv: 1,
      })
  
      const events = {
        //添加职务
        add() {
          ElMessageBox.confirm('确认新增吗').then(()=>{
            addZhiwu({
              explain:data.explain,
              lv:data.lv,
              name:data.name,
          }).then((res:any)=>{
               console.log(res);
               if(res.result===0){
                  ElMessage.success("操作成功");
                  ElMessageBox.confirm("是否还要继续新增?").then(()=>{
                        data.name='';
                  }).catch(()=>{
                    router.go(-1);
                  })
               }else{
                   ElMessage.error(res.message);
               }
               
          })
          }).catch(()=>{
           
          })
          
        },

      }
  
      onMounted(() => {
       
      })
      return {
        ...toRefs(data),
        ...events
      }
    }
  })
  </script>
    